/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import mx.core.Application;
	
	import virtPresenter.business.*;
	import virtPresenter.event.*;
	import virtPresenter.model.*;
	import virtPresenter.view.*;	
	
	/**
	 * Initializes the Application. 
	 */	
	public class InitializeApplicationCommand implements ICommand {	
		
		private var model : virtPresenterLocator = virtPresenterLocator.getInstance();	
		
		/**
		 * Execute method is invoked by the InitializeApplicationEvent.
		 * 
		 * <p> Invokes loading all needed XML files in the following order.
		 * 1. Make local connection to the presentation SWF file
		 * 2. Throw LoadLectureRecordingsXMLEvent which loads lecturerecordings.xml and throws
		 * 3. ChangedLectureEvent which sets the current lecture folder for the presentation SWF and the model and throws
		 * 4. LoadVideoXMLEvent which loads the video.xml and throws
		 * 5. LoadMouseXMLEvent which loads the mouse.xml (if available) and throws
		 * 6. LoadSearchXMLEvent which loads the search.xml and throws
		 * 7. LoadLogXMLEvent which loads logXML.xml and
		 * 8. Activates the parser and then
		 * 9. Loads the video (and immediately pauses it) to recieve the metadata so that
		 * 10. The scubber can be drawn
		 * 11. As soon as the parser is activated the SearchProvider is also able to search through the slides
		 * </p>
		 * 
		 * <p> It is strongly recommended to use this order of loading the xml files and activating the components </p>    
		 * 
		 * @parameters event InitializeApplicationEvent
		 * 
		 * @see virtPresenter.event.InitializeApplicationEvent
		 */	
		public function execute( event : CairngormEvent ): void
		{	
			//Ladereihenfolge der XML Dateien
			//
			//0. Make local connection
			//1. LoadLectureRecordingsXML --> Liefert mir die lecture folders	
			//		1.2 Throw ChangedLectureFolderEvent --> LectureFolder im SWF wird gesetzt
			//		1.3 Load videoXML		
			//				1.4 Load SearchXML
			//						1.5 Load LogXML
			//								1.6 Aktiviere den Parser
			//										1.7 Lade das Video zur Übergabe der Metadaten und lass es pausieren
			//												1.8 Zeichne den Scrubber			
			
			//Make the defaultView accessible for the model
			model.defaultView=mx.core.Application.application.defaultview;
			//Make the views ViewStack accessible for the model
			model.views=mx.core.Application.application.views;
			//Make the viewComboBox accessible for the model;
			model.viewComboBox=mx.core.Application.application.viewComboBox;
			//Make the slideBrowserView accessible for the model;
			model.slideBrowserView=mx.core.Application.application.slideOverview;
						
			//Connect the local connection to the SWF Slides (both directions).
			//This has to be done before the ChangeLectureURLEvent is dispatched.
			model.mainWindowProxy = new SlideWrapperProxy("presentationHolder","swf8connector","swf2Flex");
  			
			//Load lecturerecordings.xml
			CairngormEventDispatcher.getInstance().dispatchEvent(new LoadLectureRecordingsXMLEvent(LoadLectureRecordingsXMLEvent.LOAD_LECTURES_BY_NAME));
			
							
					
		}
							
	}
		
}
	